package server

import (
	"ehsm_kms/api"
	"ehsm_kms/internal/handler"
	"ehsm_kms/internal/middleware"
	"ehsm_kms/pkg/server/http"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

func NewHTTPServer(log *zap.Logger, config *http.Config, handler *handler.Handler) *http.Server {
	gin.SetMode(gin.DebugMode)
	s := http.NewServer(
		gin.Default(),
		log,
		config,
	)

	s.GET("/", func(ctx *gin.Context) {
		api.HandleSuccess(ctx, "eHSM kms api")
	})

	s.Use(
		middleware.CORSMiddleware(),
		middleware.RequestLogMiddleware(log),
		middleware.SignMiddleware(log, "apiKey"),
	)
	s.GET("/ehsm", handler.GET)
	s.POST("/ehsm", handler.POST)

	return s
}
